import {handlePageChange} from '../../router/index'
import Notify from '@vant/weapp/notify/notify';
const $api = require('../../request/index').API;
Page({
  data: {
    active : 0,
    img: '/icons/school_pic.JPG',
    sno: '',
    password: '',
    logined: false
  },
  onLoad() {
    var user_id = wx.getStorageSync('user_id')
    if (user_id) {
      console.log(user_id)
      this.setData({logined:true})
    } 
  },
  onPageChange(event) {

    handlePageChange(event.detail)
    // this.setData({active: event.detail})
  },
  onLogin(event) {
    console.log(this.data.sno+"\t"+this.data.password)
    $api.login({username: this.data.sno, password: this.data.password})
        .then(res => {
          console.log(res)
          wx.setStorage({
            data: res.user_id,
            key: 'user_id',
          })
          wx.setStorage({
            data: res.token,
            key: 'token',
          })
          Notify({ type: 'success', message: '登陆成功'})
          this.setData({logined:true})
        })
        .catch(err => {
          console.log(err)
        })
  }
});